package top.jacktgq.concurrent_utils.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

import top.jacktgq.utils.LogUtils;
import top.jacktgq.utils.Sleeper;

/**
 * 
 * @Title: ThreadPoolExecutorsDemo.java 
 * @Package top.jacktgq.concurrent_utils.pool 
 * @Description: 测试jdk提供的线程池
 * @author CandyWall   
 * @date 2020年11月4日 下午12:28:34 
 * @version V1.0
 */
public class ThreadPoolExecutorsDemo {
	public static void main(String[] args) {
		//ExecutorService threadPool = Executors.newFixedThreadPool(2);
		ExecutorService threadPool = Executors.newFixedThreadPool(2, new ThreadFactory() {
			private AtomicInteger tno = new AtomicInteger(1);
			@Override
			public Thread newThread(Runnable r) {
				return new Thread(r, "MyPool-Thread-" + tno.getAndIncrement());
			}
		});
		
		threadPool.execute(() -> {
			Sleeper.sleep(1);
			LogUtils.log("ThreadPoolExecutorsDemo", "1");
		});		
		threadPool.execute(() -> {
			Sleeper.sleep(1);
			LogUtils.log("ThreadPoolExecutorsDemo", "2");
		});		
		threadPool.execute(() -> {
			Sleeper.sleep(1);
			LogUtils.log("ThreadPoolExecutorsDemo", "3");
		});		
	}
}
